header-bar: Don't assume there's only one icon
authorAlexander Mikhaylenko <alexm@gnome.org>
Wed, 22 Apr 2020 16:35:32 +0000 (21:35 +0500)
committerAlexander Mikhaylenko <alexm@gnome.org>
Wed, 22 Apr 2020 18:01:12 +0000 (23:01 +0500)
Instead of tracking the titlebar icon widget, and updating it when the icon
changes, update the window buttons completely.

gtk/gtkheaderbar.c
gtk/gtkheaderbarprivate.h
gtk/gtkwindow.c

index 2280e774686006670f7ec655ed3785b2171d50e0..f34eb68facc2be0c62b7e48dd374555c770b5088 100644 (file)
@@ -126,8 +126,6 @@ struct _GtkHeaderBarPrivate
   GtkWidget *titlebar_start_separator;
   GtkWidget *titlebar_end_separator;
 
-  GtkWidget *titlebar_icon;
-
   GdkSurfaceState state;
 };
 
@@ -221,25 +219,22 @@ create_title_box (const char *title,
   return label_box;
 }
 
-gboolean
-_gtk_header_bar_update_window_icon (GtkHeaderBar *bar,
-                                    GtkWindow    *window)
+static gboolean
+update_window_icon (GtkHeaderBar *bar,
+                    GtkWindow    *window,
+                    GtkWidget    *icon)
 {
-  GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (bar);
   GdkPaintable *paintable;
   gint scale;
 
-  if (priv->titlebar_icon == NULL)
-    return FALSE;
-
-  scale = gtk_widget_get_scale_factor (priv->titlebar_icon);
+  scale = gtk_widget_get_scale_factor (icon);
   paintable = gtk_window_get_icon_for_size (window, 20 * scale);
 
   if (paintable)
     {
-      gtk_image_set_from_paintable (GTK_IMAGE (priv->titlebar_icon), paintable);
+      gtk_image_set_from_paintable (GTK_IMAGE (icon), paintable);
       g_object_unref (paintable);
-      gtk_widget_show (priv->titlebar_icon);
+      gtk_widget_show (icon);
 
       return TRUE;
     }
@@ -311,8 +306,6 @@ _gtk_header_bar_update_window_buttons (GtkHeaderBar *bar)
       priv->titlebar_end_separator = NULL;
     }
 
-  priv->titlebar_icon = NULL;
-
   if (!priv->show_title_buttons)
     return;
 
@@ -361,15 +354,13 @@ _gtk_header_bar_update_window_buttons (GtkHeaderBar *bar)
                 {
                   button = gtk_image_new ();
                   gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
-                  priv->titlebar_icon = button;
                   gtk_widget_add_css_class (button, "titlebutton");
                   gtk_widget_add_css_class (button, "icon");
 
-                  if (!_gtk_header_bar_update_window_icon (bar, window))
+                  if (!update_window_icon (bar, window, button))
                     {
                       g_object_ref_sink (button);
                       g_object_unref (button);
-                      priv->titlebar_icon = NULL;
                       button = NULL;
                     }
                 }
index 3fb3eb1e3b4fd4df5397e0f1e156dbd6d48897d5..11d8ed07487cf596a86c782eb026458652682530 100644 (file)
@@ -26,8 +26,6 @@ G_BEGIN_DECLS
 
 void         _gtk_header_bar_track_default_decoration (GtkHeaderBar *bar);
 void         _gtk_header_bar_update_window_buttons (GtkHeaderBar *bar);
-gboolean     _gtk_header_bar_update_window_icon    (GtkHeaderBar *bar,
-                                                    GtkWindow    *window);
 
 G_END_DECLS
 
index 28da604c6aaa1d17706fc2ee37450ede1a2f0d34..6793b2a9040f62559ffe67b0c922ab0718363772 100644 (file)
@@ -3432,7 +3432,7 @@ gtk_window_realize_icon (GtkWindow *window)
 
   gdk_toplevel_set_icon_list (GDK_TOPLEVEL (priv->surface), icon_list);
   if (GTK_IS_HEADER_BAR (priv->title_box))
-    _gtk_header_bar_update_window_icon (GTK_HEADER_BAR (priv->title_box), window);
+    _gtk_header_bar_update_window_buttons (GTK_HEADER_BAR (priv->title_box));
 
   if (info->using_themed_icon)
     g_list_free_full (icon_list, g_object_unref);